<%@ page import="entity.Plate" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="Impl.TopicDaoImpl" %>
<%@ page import="entity.page.IndexPage" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="entity.page.ListPage" %><%--
  Created by IntelliJ IDEA.
  User: 林不清
  Date: 2021/1/4
  Time: 10:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>帖子列表</title>
    <link rel="stylesheet" type="text/css" href="css/base.css">
    <link rel="stylesheet" type="text/css" href="css/blocknew.css">
    <script src="static/js/jquery-1.11.0.min.js"></script>
    <script src="static/js/base.js"></script>
    <script src="static/js/block.js"></script>
    <script type="text/javascript" src="static/js/index.js"></script>
</head>
<body>
<%@include file="header.jsp"%>
<%request.setCharacterEncoding("utf-8");%>
<%@include file="user_menubar.jsp"%>
<div class="container">
    <div class="main">
        <div class="title">
            <h2><span><img src="img/list-all-icon.png" style="width: 25px; height: 18px; margin-bottom: 2px"/></span>所有内容</h2>
        </div>
        <div class="post-list">
            <%--      在这里放数据      --%>
            <% if ((boolean)request.getAttribute("isFather")) {
                ArrayList<Plate> listSections = (ArrayList<Plate>) request.getAttribute("listSections");
            %>
            <%--        如果是根版块        --%>
            <table cellspacing="0" cellpadding="0" width="100%">

                <tr class="tr2">
                    <td>&nbsp;</td>
                    <td style="width: 20%" align="center">论坛</td>
                    <td style="width: 50%" align="center">主题</td>
                    <td style="width: 30%" align="center">最后发表</td>
                </tr>

                <%for (int i = 0; i < listSections.size(); i++) {
                    TopicDaoImpl  topicDao = new TopicDaoImpl();
                    IndexPage indexPage = topicDao.getALLTopicLastTimeById(listSections.get(i).getSid());
                    Integer sid = listSections.get(i).getSid();
                    System.out.println("模块的ID："+sid);
                    Integer tid = indexPage.getTid();
                    String topicName = indexPage.getTtopic();
                    Date topicPublishTime = indexPage.getTpublishtime();
                    String topicAuthor = indexPage.getAuthor();
                %>

                <tr class="tr3">
                    <td><img src="img/topic.gif" border=0></td>
                    <td style="font-size: 15px">
                        <a href="showList.jhtml?sid=<%=listSections.get(i).getSid()%>">
                            <%=listSections.get(i).getsName()%></a>
                    </td>
                    <td align="center"><%=listSections.get(i).getsTopicCount()%></td>
                    <%if (topicPublishTime != null) {
                        String formateTopicPublishTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(topicPublishTime);
                    %>
                    <td align="center"><a href="showArticle.jhtml?sid=<%=sid%>&tid=<%=tid%>"><%=topicName%></a>&nbsp;&nbsp;&nbsp;
                        <%=topicAuthor%><br>
                        <%=formateTopicPublishTime%>
                    </td>
                    <%} else {%>
                    <td align="center">暂无</td>
                    <%}%>
                </tr>

                <%}%>


            </table>


            <%} else {
                ArrayList<ListPage> listPages = (ArrayList<ListPage>) request.getAttribute("listPage");
            %>
            <%--        如果是普通版块        --%>
            <table cellspacing="0" cellpadding="0" width="100%">

                <tr class="tr2">
                    <td>&nbsp;</td>
                    <td style="width: 80%" align="center">文章</td>
                    <td style="width: 10%" align="center">作者</td>
                    <td style="width: 10%" align="center">回复</td>
                </tr>

                <%for (int i = 0; i < listPages.size(); i++){

                %>

                <tr class="tr3">
                    <td><img src="img/topic.gif" border=0></td>
                    <td style="font-size: 15px">
                        <a href="/showArticle.jhtml?tid=<%=listPages.get(i).getTid()%>&sid=<%=request.getSession().getAttribute("sid")%>&action=showDetail">
                            <%=listPages.get(i).getTitle()%></a>
                    </td>
                    <td align="center"><%=listPages.get(i).getAuthor()%></td>
                    <td align="center"><%=listPages.get(i).getReplycount()%></td>
                </tr>
                <%}%>

            </table>


            <%}%>

        </div>

        <% if (!(boolean) request.getAttribute("isFather")) {%>


        <div style="margin-left: 250px; margin-top: 20px" id="count_page">

            <span>共有<%=request.getAttribute("allpage") %>页</span>
            <span style="margin-left:150px">第<%=request.getAttribute("pageNow")%>页</span>&nbsp;&nbsp;
            <a href="showList.jhtml?sid=<%=request.getSession().getAttribute("sid")%>&pageNow=1">首页</a>
            <%if((int)request.getAttribute("pageNow")>1){ %>
            <a href="showList.jhtml?sid=<%=request.getSession().getAttribute("sid")%>&pageNow=<%=(int)request.getAttribute("pageNow")-1%>">上一页</a>
            <%
                }
            %>

            <%
                if ((int) request.getAttribute("pageNow") < (int) request.getAttribute("allpage")) {
            %>

            <a href="showList.jhtml?sid=<%=request.getSession().getAttribute("sid")%>&pageNow=<%=(int)request.getAttribute("pageNow")+1%>">下一页</a>

            <%} %>

            <a href="showList.jhtml?sid=<%=request.getSession().getAttribute("sid")%>&pageNow=<%=(int)request.getAttribute("allpage")%>">末页</a>

        </div>

        <%}%>

    </div>
</div>
</body>
</html>
